//第3关 编写一个学生类

package step3;

public class Student {
	private int num;
	private String name;
	private int age;
	                                               
	public Student() {
		
	}

	
	public Student(int num, int age, String name) {
		super();
		this.num = num;
		this.age = age;
		this.name = name;
	}

	public int getNum() {
		return num;
	}


	public void setNum(int num) {
		this.num = num;
	}


	public String getName() {
		return name;
	}


	public void setName(String name) {
		this.name = name;
	}


	public int getAge() {
		return age;
	}


	public void setAge(int age) {
		this.age = age;
	}


	@Override
	public String toString() {
		return "学号:" + num + ",姓名:" + name + ",年龄:" + age;
	}


	public static void main(String args[]) {
		Student s1 = new Student(1, 18, "小明");
		Student s2 = new Student(2, 20, "小张");
		Student s3 = new Student(3, 19, "小李");
		Student s4 = new Student(4, 18, "小王");
		Student s5 = new Student(5, 20, "小赵");

		Student s[] = { s1, s2, s3, s4, s5 }; // 给对象数组赋值
		System.out.println("班级学生名单如下：");
		output(s); // 第1次调用output方法输出数组
		/********** Begin **********/
		// 将所有学生年龄加 1
		for (int i = 0; i < s.length; i++) {
			s[i].age += 1;
		}

		/********** End **********/                             
		System.out.println("所有学生年龄加 1 后...");
		output(s); /// 第2次调用output方法输出数组
		int count = 0;
		/********** Begin **********/
		//统计大于20岁的学生个数
		for (int i = 0; i < s.length; i++) {
			if (s[i].age > 20) {
				count++;
			}
		}
		/********** End **********/                    
		System.out.println("大于 20 岁人数是：" + count);
	}

	/* 以下方法输岀学生数组的所有元素 */
	private static void output(Student s[]) {
		for (int i = 0; i < s.length; i++)
			System.out.println(s[i]);
	}
}